package com.bole.service.impl;

import com.bole.pojo.LeavingDo;
import com.bole.service.LeaveMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class LeaveMessageServiceImpl implements LeaveMessageService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public List<LeavingDo> getMessageBySellUserId(Long sellUserId) {
        Query query = new Query(Criteria.where("SellUserId").is(sellUserId));
        return mongoTemplate.find(query, LeavingDo.class);
    }

    @Override
    public void saveLeavingMessage(LeavingDo leavingDo) {
        leavingDo.setMessageTime(new Date());
        mongoTemplate.save(leavingDo);
    }
}
